const { DataTypes } = require("sequelize");
const sequelize = require("./index");

const Order = sequelize.define(
    "order",
    {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            allowNull: false,
            autoIncrement: true,
        },
        productId: {
            type: DataTypes.INTEGER,
            allowNull: false,
        },
        userId: {
            type: DataTypes.INTEGER,
            allowNull: false,
        },
        createTime: {
            type: DataTypes.DATE,
            defaultValue: new Date(),
        },
        status: {
            type: DataTypes.INTEGER,
            defaultValue: 0,
            comment: "0:已下单；1：发货；2：收货；3：已评价",
        },
        position: {
            type: DataTypes.STRING,
            defaultValue: "",
        },
    },
    {
        timestamps: false,
    }
);

Order.associate = function ({ User, Product }) {
    Order.belongsTo(User);
    Order.belongsTo(Product);
};

module.exports = Order;
